package com.example.iqiyitest.hztvpaysdk;


public class SecurityUtil {
    private static final char[] HEX_UPPER_CHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    private static final char[] HEX_CHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public static String bytes2UpperHex(byte[] bytes) {
        if (null == bytes || bytes.length <= 0) {
            throw new IllegalArgumentException("bytes is null or empty!");
        }
        char[] resultChars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            resultChars[i * 2] = HEX_UPPER_CHARS[bytes[i] >>> 4 & 0x0f];
            resultChars[i * 2 + 1] = HEX_UPPER_CHARS[bytes[i] & 0x0f];
        }
        return new String(resultChars);
    }

    public static String bytes2Hex(byte[] bytes) {
        if (null == bytes || bytes.length <= 0) {
            throw new IllegalArgumentException("bytes is null or empty!");
        }
        char[] resultChars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            resultChars[i * 2] = HEX_CHARS[bytes[i] >>> 4 & 0x0f];
            resultChars[i * 2 + 1] = HEX_CHARS[bytes[i] & 0x0f];
        }
        return new String(resultChars);
    }
}
